Repository navigation
Conversation
|
Ergh, I see the build failed on Node v0.8.28 and v0.10.48 with precisely the error I was trying to patch away. I have no idea why… Does this project actively support those long-EOL-ed releases? |
dougwilson
left a comment
There was a problem hiding this comment.
Hi @theneva it does in the current major version; dropping major versions of Node.js would be a major version bump for us, but in addition, the official Express middlewares support the same versions that the current version of Express itself supports (so that makes them usable in the same versions Express is).
In addition to the test failure, it seems like this doesn't completely fix the support, as according to the Node.js documentation for res.end, the callback can be not just argument 1, but also argument 2 and argument 3: https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_request_end_data_encoding_callback
I took a look locally and the fix also only seems to work if you're not actually modifying the session. If the session is modified, it goes back to not working with the callback again, so it seems like there is more work to do here.
|
looking into build failure ... |
|
Hm, I guess I only solved my own case here 😄 I'll have another look at this tomorrow! Thanks for taking a look! And thank you very much @ghinks, it would be super helpful if you found something! It doesn't look like the Edit: Oh, typeof doesn't work… I'll work around that, then 🙂 |
|
yes, I'm surprised by the fail too. I thought this was part of the language. |
|
Had another look!
The builds are failing because I suppose this is why the main Express docs on
… and link to the latest Node (14.2.0) docs. This led me to believe there was an error in the Express docs, as I noted in the original post. Versions prior to 0.11.6 (including both 0.8 and 0.10, obviously) simply check if
If you're okay with this approach, I'll try to make it work regardless of whether you modify the session, and the various supported permutations of arguments. What do you think? |
|
Hi @theneva thanks for taking a deep look! All of that sounds good, except about the warnings part. I would say the goal I think would be to have |
|
Alright, sounds good! I'll take another stab at it tomorrow, then. |
|
Oh, forgot to comment on the |
|
Linking for context, here's a PR tackling very nearly the same issue over in |
|
Thanks, @jonchurch! I think I'm pretty close to coming up from the rabbit hole that is undocumented To anyone subscribed to e-mails about new commits being pushed, sorry! I've been fiddling with this on and off using two different computers, and I guess there's no nice way to avoid notifying everyone. I'll convert the PR to a draft now in case that helps. I think I'm very close something that works & can be reviewed/discussed now. |
|
@dougwilson I think I finally have something that works as intended now, with tests for all cases. As it turns out, there's a lot of undocumented and/or weird behaviour in old versions of Node. The coverage check fails because of some error handling I had to introduce to write tests. I'm not too happy about how that turned out, so I'd very much like to know if you can think of a better way to do the error handling before I spend more time trying to get it covered by the tests. There is a very minor difference between the original res#end and the proxy, in that calling I'm also not too happy about all the code duplication in the tests, but I couldn't find an elegant way to test multiple cases at once. It would be awesome if you took another look at the code! |
| chunk = !Buffer.isBuffer(chunk) | ||
| ? Buffer.from(chunk, encoding) | ||
| : chunk; | ||
| endArgs[0] = chunk; |
There was a problem hiding this comment.
Since we pass endArgs to the original _end(), we need to keep it up to date. I believe the chunk is reassigned here because Node 0.8's end() only accepts a Buffer?
Mutating a function's arguments feels pretty bad, but it's by far the most elegant solution I came up with.
I'm not sure if this warrants a comment in the code.
|
Hi @theneva I just wanted to write in here that I haven't forgotten about this PR; it is just quite complicated, and really appreciate all the work you did on it :) I am just trying to wrap my head around some of the items in here where you have questions in order to get you some answers. |
|
Heh, yeah, it turned into a lot. For what it's worth, I've worked around the issue, so it's not hugely important to me that this lands. It's wrong, but maybe the added complexity isn't worth it... |
|
At some level it is worth fixing, but I know we have gotten away with not fixing it just because I guess the feature is rarely used. But of course this still breaks the callback feature, so should be fixed. |
|
Yeah. I think the worst part for me was how hard this was to debug and pinpoint the issue, but fixing it would obviously be best :) |
9d2e29b to
408229e
Compare
|
@dougwilson do you still think this is worth fixing? 😄 one way or the other, I'd like to get this out of my open pull requests |
yxshee
left a comment
There was a problem hiding this comment.
I rebased this locally onto current master (178 commits behind; it merges without conflicts) and ran it on Node 26: 176 passing. Two of the three new tests fail on master (callback as the only argument throws ERR_INVALID_ARG_TYPE, callback as the third argument is never called). The second-argument test also passes on master.
On the 2020 point that the callback was still lost once the session is modified, I ran each of res.end(cb), res.end('hello', cb), res.end('hello', 'utf8', cb) and res.end(buf, cb) in four states: new and unmodified, modified (store.set), destroyed, and an existing session that is only touched.
- master:
res.end('hello', 'utf8', cb)never callscbin any of the four states, andres.end(cb)throwsERR_INVALID_ARG_TYPEin the modified and touched states. - this branch: the callback runs and the body is right in all 16 cases.
Two things are left before CI would pass:
npm run lintreports 2 errors: the indentation of the nested ternary (index.js:288-289 after merging master).- The three new
try { writeend() } catch (err) { next(err) }blocks are never hit on current Node, so index.js line coverage goes from 100% to 99% (lines 371, 399 and 416). They also callnext(err)after the response has started ending, which could lead to a second response. If they are only there for the Node 0.8/0.10 test path, it might be simpler to drop them.
I could not run the 0.8/0.10 jobs locally, so I have not checked the version-gated assertions.
|
Thank you very much, @yxshee!
Wild. I don't feel much ownership of this PR anymore (it's been six and a half years!), but from the sidelines: Surely support for v0.8/v0.10 doesn't matter anymore? As far as I can tell from the table on the EOL page, the final update to any v0 version was February 22, 2017. Even herodevs (referenced under "Commercial support" on the EOL page) supports only version 12 and up. v0.8/v0.10 support already felt almost irrelevant back in 2020, so not being able to run those jobs now shouldn't block this PR 😄 … and/but if those versions are no longer relevant, could we get away with keeping only the very first commit on this branch? I'm almost certain all the subsequent commits were related to v0.x support. Thoughts? |
Hi! 👋
This fixes #477. It bit me, and figuring out what broke in my application took forever, so I figured I'd try to fix it.
I'm not familiar with this code base at all, so please excuse any style breaches!
The test I added fails without the changes to
index.js, and all the tests pass with the changes.I will also attempt sending a PR updating the
expressdocs onres.end([data] [, encoding])at https://expressjs.com/en/api.html#res, as they seem to suggest thatres.enddoes not take a callback. It does!Let me know if anything looks off!